package com.ddwl.goods.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.goods.QueryGoodsProfitBo;
import com.ddwl.goods.service.GoodsProfitService;
import com.ddwl.schema.bo.distr.ComputeProfitPriceBo;
import com.ddwl.schema.bo.distr.SetGoodsProfitBo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.dist.ComputeProfitPriceVo;
import com.ddwl.schema.vo.dist.GoodsProfitVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 类GoodsProfitController.java的实现描述：商品分润设置接口
 *
 * @author zach
 * @Date :2020-05-25 15:52.
 */
@Api(tags = "分润信息")
@RequestMapping("/profit")
@RestController
public class GoodsProfitController extends BaseController {

    @Resource
    private GoodsProfitService goodsProfitService;

    @PostMapping("/set")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    @ApiOperation("设置商品分润")
    public RestVo SetGoodsProfitVo(@Valid @RequestBody SetGoodsProfitBo goodsProfitVo) {
        goodsProfitService.setGoodsProfit(goodsProfitVo);
        return RestVo.ok();
    }

    @DeleteMapping("/delete")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    @ApiOperation("删除商品分润")
    public RestVo deleteGoodsProfitVo(@ApiParam(value = "商品分润id", required = true) @RequestParam String id ) {
        goodsProfitService.deleteGoodsProfit(id);
        return RestVo.ok();
    }

    @GetMapping("/query")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE,BaseEnum.ProductEnum.MALL})
    @ApiOperation("查询商品分润信息")
    public RestVo<List<GoodsProfitVo>> queryGoodsProfitVo(@Valid QueryGoodsProfitBo queryGoodsProfitVo) {
        return RestVo.ok(goodsProfitService.queryGoodsProfitVo(queryGoodsProfitVo));
    }

    @PostMapping("/profitPrice")
    @Auth(product = {BaseEnum.ProductEnum.API})
    @ApiOperation(value = "计算获取商品的分润金额")
    public RestVo<List<ComputeProfitPriceVo>> computeProfitPrice(@RequestBody List<ComputeProfitPriceBo> itemBos) {
        return RestVo.ok(goodsProfitService.computeProfitPrice(itemBos));
    }
}
